<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/Warsaw');

//Disable magiq quotes
if (get_magic_quotes_gpc()) {
    function stripslashes_deep($value)
    {
        $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
        return $value;
    }
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}

$config = require_once APP_ROOT . '/system/config.php';

//set include paths
$paths = implode(PATH_SEPARATOR, array(
    $config['path']['libs'],
    $config['path']['models'],
    $config['path']['system'],
    $config['path']['app']
));
set_include_path($paths);

//setup Zend_Loader
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

//setup Doctrine autoload
spl_autoload_register(array('Doctrine', 'autoload'));

//setup Doctrine
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);

Doctrine::debug(true);

$connection_string =
    $config['db']['type'].'://'.
    $config['db']['params']['username'].':'.
    $config['db']['params']['password'].'@'.
    $config['db']['params']['host'].'/'.
    $config['db']['params']['dbname'];

//set up the connection
if(!($conn = $manager->connection($connection_string)))
    die('Database connection failed');

return $config;   
